// UsesProcTable.cpp : stores the variables used in each procedure.
// Author: Achyut P Balaji
//

#include"UsesProcTable.h"

/*Description: Private Constructor if class UsesProcTable.*/
UsesProcTable::UsesProcTable() {
	initialised = false;
}

void UsesProcTable::initial(int size) {
	vector<VAR_INDEX> temp1;
	for(int i=0;i<size;i++) {
		variablesUsed.push_back(temp1);
	}
}

UsesProcTable* UsesProcTable::obj = NULL;

/*Description: This function is used to get the object of the class UsesProcTable.
Implements the Singleton Design Pattern and prevents decleration of anymore objects of this class. */
UsesProcTable* UsesProcTable::getInstance(){
		if(!obj) 
			obj = new UsesProcTable;
		return obj;
}

/*Description: This function is used to reinitialise the object of the class UsesProcTable.
Implements the Singleton Design Pattern and prevents decleration of anymore objects of this class. */
UsesProcTable* UsesProcTable::getFirstInstance(){
		obj = new UsesProcTable;
		return obj;
}

BOOLEAN UsesProcTable::addEntry(PROC_INDEX n, VAR_LIST varUsed) {
	for(unsigned int i=0;i<varUsed.size();i++) {
		bool temp = false;
		for(unsigned int j=0;j<variablesUsed.at(n).size();j++) {
			if(varUsed.at(i) == variablesUsed.at(n).at(j)) {
				temp = true;
			}
		}
		if(temp == false) {
			variablesUsed.at(n).push_back(varUsed.at(i));
		}
	}
	return true;
}

BOOLEAN UsesProcTable::isUsed(PROC_INDEX n, VAR_INDEX ind) {

	for(unsigned int i=0;i<variablesUsed.at(n).size();i++) {
		if(ind == variablesUsed.at(n).at(i)) {
			return true;
		}
	}
	return false;
}

VAR_LIST* UsesProcTable::getVarUsed(PROC_INDEX n) {
		return &variablesUsed[n];
}


void UsesProcTable::initialise() {
	initialised = true;
}